package me.linkcn.ydtxl.web.resource;

import me.linkcn.ydtxl.web.objects.Account;
import org.restlet.data.CharacterSet;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.Post;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: cmcc
 * Date: 11-8-17
 * Time: 下午4:47
 */
public class AccountsResource extends BaseResource {
    @Post
    public Representation checkLogin(Representation input) {
        ClientResource clientResource = new ClientResource(getServerUri() + "/account");
        Representation reply = clientResource.put(input);
        if (reply.isAvailable()) {
            JacksonRepresentation<Account> accountRep = new JacksonRepresentation<Account>(reply, Account.class);
            Account account = accountRep.getObject();
            //getResponse().redirectSeeOther(getRequest().getResourceRef());
            return generateRedirectRepresentation(getRequest().getResourceRef().toString().replace("/account", "/" + account.getAccountName()));
        } else {
            return generateErrorRepresentation("错误的用户名或密码！", "1");
        }
    }
}
